﻿/*
 ===============================================================================
 *文件名称(File Name)：MD5
 *功能描述(Description)：
 *数据表(Tables)：
 *作者(Author)：第八个男人
 *日期(Create Date)：2016/1/22 21:54:48
 *修改记录(Revision History)：
 * V1.0.0.0 Created by 第八个男人 at 2016/1/22 21:54:48
 ===============================================================================
 */

using System.Security.Cryptography;
using System.Text;

namespace Utility.Encryption
{
    public static class HashHelper
    {
        /// <summary>
        /// 将字符串加密为Md5
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string GetMd5(this string str)
        {
            ASCIIEncoding enc = new ASCIIEncoding();
            byte[] buffer = enc.GetBytes(str);
            MD5 md5 = new MD5CryptoServiceProvider();
            byte[] hash = md5.ComputeHash(buffer);
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < hash.Length; i++)
            {
                sb.AppendFormat("{0:x2}", hash[i]);
            }
            return sb.ToString().ToUpper();
        }
    }
}